﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Collections;
using cfg = System.Configuration;
using GoldPrinter;
using Infragistics.Win;
using Infragistics.Win.UltraWinGrid;
using Infragistics.Win.UltraWinCalcManager;
using Infragistics.Win.CalcEngine;
using WeifenLuo.WinFormsUI.Docking;

namespace BYManageInfoSystem
{
    //1.未回收
    //2.空白
    //3.假
    //4.真
    public partial class Frm_BackRecoveryMaterialResgistTab : DockContent
    {
        private DGBY.BLL.DG_BackRecoveryMaterialResgistTab m_bllBackRecoveryMaterialResgistTab = new DGBY.BLL.DG_BackRecoveryMaterialResgistTab();
        private DGBY.BLL.ConstantJudgmentTab m_bllBConstantJudgmentTab = new DGBY.BLL.ConstantJudgmentTab();
        private DGBY.BLL.HxdNoTab m_bllHxdNoTab = new DGBY.BLL.HxdNoTab();
        Dictionary<int, int> m_dicSelectID2RowNo = new Dictionary<int, int>();
        CheckBoxOnHeader_CreationFilter aCheckBoxOnHeader_CreationFilter = new CheckBoxOnHeader_CreationFilter();
        private bool m_bLastModifiedCellIsSelect = false;
        Hashtable m_SQLStringList = new Hashtable();
        ArrayList m_arrayList = new ArrayList();
        private DGBY.BLL.SJPackingTab m_bllSJPackingTab = new DGBY.BLL.SJPackingTab();
        bool m_bHiddenBackInfo = false;
        string m_strSqlConditions;

        public Frm_BackRecoveryMaterialResgistTab()
        {
            InitializeComponent();
        }

        private void Frm_BackRecoveryMaterialResgistTab_Load(object sender, EventArgs e)
        {
            ClassUltraGridCommonSet.InitUltraWinGridSetting(this.ultraGrid1);

            this.ultraGrid1.CreationFilter = aCheckBoxOnHeader_CreationFilter;
            aCheckBoxOnHeader_CreationFilter.SetParam(m_dicSelectID2RowNo, this.ultraGrid1);

            InitUltraDropDown();

            FormLoadShowRecord();
        }

        private void InitUltraDropDown()
        {
            DataSet dsTemp = m_bllBConstantJudgmentTab.GetList("");

            this.ultraDropDowntd.DataSource = dsTemp.Tables[0];
            this.ultraDropDowntd.DisplayMember = "ConstantJudgmentValue";
            this.ultraDropDowntd.ValueMember = "ConstantJudgmentTabID";
            for (int i = 0; i < this.ultraDropDowntd.DisplayLayout.Bands[0].Columns.Count; i++)
                this.ultraDropDowntd.DisplayLayout.Bands[0].Columns[i].Hidden = true;
            this.ultraDropDowntd.DisplayLayout.Bands[0].Columns["ConstantJudgmentValue"].Hidden = false;
            this.ultraDropDowntd.DisplayLayout.Bands[0].ColHeadersVisible = false;

            this.ultraDropDownrcd.DataSource = dsTemp.Tables[0];
            this.ultraDropDownrcd.DisplayMember = "ConstantJudgmentValue";
            this.ultraDropDownrcd.ValueMember = "ConstantJudgmentTabID";
            for (int i = 0; i < this.ultraDropDownrcd.DisplayLayout.Bands[0].Columns.Count; i++)
                this.ultraDropDownrcd.DisplayLayout.Bands[0].Columns[i].Hidden = true;
            this.ultraDropDownrcd.DisplayLayout.Bands[0].Columns["ConstantJudgmentValue"].Hidden = false;
            this.ultraDropDownrcd.DisplayLayout.Bands[0].ColHeadersVisible = false;

            this.ultraDropDownlld.DataSource = dsTemp.Tables[0];
            this.ultraDropDownlld.DisplayMember = "ConstantJudgmentValue";
            this.ultraDropDownlld.ValueMember = "ConstantJudgmentTabID";
            for (int i = 0; i < this.ultraDropDownlld.DisplayLayout.Bands[0].Columns.Count; i++)
                this.ultraDropDownlld.DisplayLayout.Bands[0].Columns[i].Hidden = true;
            this.ultraDropDownlld.DisplayLayout.Bands[0].Columns["ConstantJudgmentValue"].Hidden = false;
            this.ultraDropDownlld.DisplayLayout.Bands[0].ColHeadersVisible = false;

            this.ultraDropDowntyd.DataSource = dsTemp.Tables[0];
            this.ultraDropDowntyd.DisplayMember = "ConstantJudgmentValue";
            this.ultraDropDowntyd.ValueMember = "ConstantJudgmentTabID";
            for (int i = 0; i < this.ultraDropDowntyd.DisplayLayout.Bands[0].Columns.Count; i++)
                this.ultraDropDowntyd.DisplayLayout.Bands[0].Columns[i].Hidden = true;
            this.ultraDropDowntyd.DisplayLayout.Bands[0].Columns["ConstantJudgmentValue"].Hidden = false;
            this.ultraDropDowntyd.DisplayLayout.Bands[0].ColHeadersVisible = false;

            this.ultraDropDownfxt.DataSource = dsTemp.Tables[0];
            this.ultraDropDownfxt.DisplayMember = "ConstantJudgmentValue";
            this.ultraDropDownfxt.ValueMember = "ConstantJudgmentTabID";
            for (int i = 0; i < this.ultraDropDownfxt.DisplayLayout.Bands[0].Columns.Count; i++)
                this.ultraDropDownfxt.DisplayLayout.Bands[0].Columns[i].Hidden = true;
            this.ultraDropDownfxt.DisplayLayout.Bands[0].Columns["ConstantJudgmentValue"].Hidden = false;
            this.ultraDropDownfxt.DisplayLayout.Bands[0].ColHeadersVisible = false;

            this.ultraDropDownwts.DataSource = dsTemp.Tables[0];
            this.ultraDropDownwts.DisplayMember = "ConstantJudgmentValue";
            this.ultraDropDownwts.ValueMember = "ConstantJudgmentTabID";
            for (int i = 0; i < this.ultraDropDownwts.DisplayLayout.Bands[0].Columns.Count; i++)
                this.ultraDropDownwts.DisplayLayout.Bands[0].Columns[i].Hidden = true;
            this.ultraDropDownwts.DisplayLayout.Bands[0].Columns["ConstantJudgmentValue"].Hidden = false;
            this.ultraDropDownwts.DisplayLayout.Bands[0].ColHeadersVisible = false;

            dsTemp = m_bllBConstantJudgmentTab.GetList(" ConstantJudgmentTabID = 1 or ConstantJudgmentTabID = 4");
            this.ultraDropDownCkht.DataSource = dsTemp.Tables[0];
            this.ultraDropDownCkht.DisplayMember = "ConstantJudgmentValue";
            this.ultraDropDownCkht.ValueMember = "ConstantJudgmentTabID";
            for (int i = 0; i < this.ultraDropDownCkht.DisplayLayout.Bands[0].Columns.Count; i++)
                this.ultraDropDownCkht.DisplayLayout.Bands[0].Columns[i].Hidden = true;
            this.ultraDropDownCkht.DisplayLayout.Bands[0].Columns["ConstantJudgmentValue"].Hidden = false;
            this.ultraDropDownCkht.DisplayLayout.Bands[0].ColHeadersVisible = false;
        }

        private void FormLoadShowRecord()
        {
            m_strSqlConditions = @" T_ACL_User.ID = '" + Frm_Main.m_nLoginUserId + @"' and ((DG_BackRecoveryMaterialResgistTab.td = 1 
                    or DG_BackRecoveryMaterialResgistTab.rcd = 1
                    or DG_BackRecoveryMaterialResgistTab.lld = 1
                    or DG_BackRecoveryMaterialResgistTab.tyd = 1
                    or DG_BackRecoveryMaterialResgistTab.fxt = 1
                    or DG_BackRecoveryMaterialResgistTab.wts = 1
                    or DG_BackRecoveryMaterialResgistTab.ckht = 1)
                    or ((DG_BackRecoveryMaterialResgistTab.td > 2 and  year(HxdNoTab.HstddjDate) = 1900)
                    or (DG_BackRecoveryMaterialResgistTab.rcd > 2 and year(HxdNoTab.HSLCDDate) = 1900)
                    or (DG_BackRecoveryMaterialResgistTab.lld > 2 and year(HxdNoTab.HSLLDDate) = 1900)
                    or (DG_BackRecoveryMaterialResgistTab.tyd > 2 and year(HxdNoTab.HSTYDDate) = 1900)
                    or (DG_BackRecoveryMaterialResgistTab.fxt > 2 and year(HxdNoTab.HsbdzldjDate) = 1900)
                    or (DG_BackRecoveryMaterialResgistTab.wts > 2 and year(HxdNoTab.QtddjDate) = 1900)
                    or (DG_BackRecoveryMaterialResgistTab.ckht > 2 and year(HxdNoTab.SCKHTdjDate) = 1900)))";

            ShowAllRecord(m_strSqlConditions);
        }

        private void buttonShow_Click(object sender, EventArgs e)
        {
            m_strSqlConditions = " T_ACL_User.ID = '" + Frm_Main.m_nLoginUserId
                + @"' and DG_BackRecoveryMaterialResgistTab.bCannotRecover != 1 
                    and (DG_BackRecoveryMaterialResgistTab.td = 1 
                    or DG_BackRecoveryMaterialResgistTab.rcd = 1
                    or DG_BackRecoveryMaterialResgistTab.lld = 1
                    or DG_BackRecoveryMaterialResgistTab.tyd = 1
                    or DG_BackRecoveryMaterialResgistTab.fxt = 1
                    or DG_BackRecoveryMaterialResgistTab.wts = 1
                    or DG_BackRecoveryMaterialResgistTab.ckht = 1)";

            ShowAllRecord(m_strSqlConditions);
        }
        private void button1_Click(object sender, EventArgs e)
        {
            m_strSqlConditions = " T_ACL_User.ID = '" + Frm_Main.m_nLoginUserId + "'";

            ShowAllRecord(m_strSqlConditions);
        }
        private void buttonShowAll_Click(object sender, EventArgs e)
        {
            m_strSqlConditions = "";
            ShowAllRecord(" ");
        }

        private void ShowAllRecord(string strWhere)
        {
            m_dicSelectID2RowNo.Clear();

            DataSet ds = m_bllBackRecoveryMaterialResgistTab.ShowBackRecoveryMaterial(strWhere);
            ultraGrid1.DataSource = null;
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                ultraGrid1.DataSource = ds.Tables[0];
                ultraGrid1.DisplayLayout.Bands[0].Columns["DG_BackRecoveryMaterialResgistTabID"].Hidden = true;
                ultraGrid1.DisplayLayout.Bands[0].Columns["HxdNoTabID"].Hidden = true;

                ultraGrid1.DisplayLayout.Bands[0].Columns["回收提单登记日期"].Hidden = true;
                ultraGrid1.DisplayLayout.Bands[0].Columns["入仓单回收日期"].Hidden = true;
                ultraGrid1.DisplayLayout.Bands[0].Columns["六联单回收日期"].Hidden = true;
                ultraGrid1.DisplayLayout.Bands[0].Columns["托运单回收日期"].Hidden = true;
                ultraGrid1.DisplayLayout.Bands[0].Columns["回收放行条登记日期"].Hidden = true;
                ultraGrid1.DisplayLayout.Bands[0].Columns["委托书回收日期"].Hidden = true;
                ultraGrid1.DisplayLayout.Bands[0].Columns["收出口合同登记日期"].Hidden = true;

                this.ultraGrid1.DisplayLayout.Bands[0].Columns["提单"].ValueList = this.ultraDropDowntd;
                this.ultraGrid1.DisplayLayout.Bands[0].Columns["入仓单"].ValueList = this.ultraDropDownrcd;
                this.ultraGrid1.DisplayLayout.Bands[0].Columns["六联单"].ValueList = this.ultraDropDownlld;
                this.ultraGrid1.DisplayLayout.Bands[0].Columns["托运单"].ValueList = this.ultraDropDowntyd;
                this.ultraGrid1.DisplayLayout.Bands[0].Columns["放行条"].ValueList = this.ultraDropDownfxt;
                this.ultraGrid1.DisplayLayout.Bands[0].Columns["委托书"].ValueList = this.ultraDropDownwts; 
                this.ultraGrid1.DisplayLayout.Bands[0].Columns["出口合同"].ValueList = this.ultraDropDownCkht;

                ultraGrid1.DisplayLayout.Bands[0].Columns["确认签收"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.Button;

                int nTemp = 0;
                DateTime? dtTemp;
                for (int i = 0; i < ds.Tables[0].Rows.Count; ++i)
                {
                    UltraGridRow CurrentUGR = this.ultraGrid1.Rows[i];

                    Color clorDefault = CurrentUGR.Cells["全选"].Appearance.BackColor; 

                    nTemp = Convert.ToInt32(ds.Tables[0].Rows[i]["提单"]);
                    dtTemp = Convert.ToDateTime(ds.Tables[0].Rows[i]["回收提单登记日期"]);
                    if (nTemp > 2 && 1900 != dtTemp.Value.Date.Year)
                    {
                        CurrentUGR.Cells["提单"].Appearance.BackColor = Color.Gray;
                    }
                    else
                    {
                        CurrentUGR.Cells["提单"].Appearance.BackColor = clorDefault;
                    }

                    nTemp = Convert.ToInt32(ds.Tables[0].Rows[i]["入仓单"]);
                    dtTemp = Convert.ToDateTime(ds.Tables[0].Rows[i]["入仓单回收日期"]);
                    if (nTemp > 2 && 1900 != dtTemp.Value.Date.Year)
                    {
                        CurrentUGR.Cells["入仓单"].Appearance.BackColor = Color.Gray;
                    }
                    else
                    {
                        CurrentUGR.Cells["入仓单"].Appearance.BackColor = clorDefault;
                    }

                    nTemp = Convert.ToInt32(ds.Tables[0].Rows[i]["六联单"]);
                    dtTemp = Convert.ToDateTime(ds.Tables[0].Rows[i]["六联单回收日期"]);
                    if (nTemp > 2 && 1900 != dtTemp.Value.Date.Year)
                    {
                        CurrentUGR.Cells["六联单"].Appearance.BackColor = Color.Gray;
                    }
                    else
                    {
                        CurrentUGR.Cells["六联单"].Appearance.BackColor = clorDefault;
                    }

                    nTemp = Convert.ToInt32(ds.Tables[0].Rows[i]["托运单"]);
                    dtTemp = Convert.ToDateTime(ds.Tables[0].Rows[i]["托运单回收日期"]);
                    if (nTemp > 2 && 1900 != dtTemp.Value.Date.Year)
                    {
                        CurrentUGR.Cells["托运单"].Appearance.BackColor = Color.Gray;
                    }
                    else
                    {
                        CurrentUGR.Cells["托运单"].Appearance.BackColor = clorDefault;
                    }

                    nTemp = Convert.ToInt32(ds.Tables[0].Rows[i]["放行条"]);
                    dtTemp = Convert.ToDateTime(ds.Tables[0].Rows[i]["回收放行条登记日期"]);
                    if (nTemp > 2 && 1900 != dtTemp.Value.Date.Year)
                    {
                        CurrentUGR.Cells["放行条"].Appearance.BackColor = Color.Gray;
                    }
                    else
                    {
                        CurrentUGR.Cells["放行条"].Appearance.BackColor = clorDefault;
                    }

                    nTemp = Convert.ToInt32(ds.Tables[0].Rows[i]["委托书"]);
                    dtTemp = Convert.ToDateTime(ds.Tables[0].Rows[i]["委托书回收日期"]);
                    if (nTemp > 2 && 1900 != dtTemp.Value.Date.Year)
                    {
                        CurrentUGR.Cells["委托书"].Appearance.BackColor = Color.Gray;
                    }
                    else
                    {
                        CurrentUGR.Cells["委托书"].Appearance.BackColor = clorDefault;
                    }

                    nTemp = Convert.ToInt32(ds.Tables[0].Rows[i]["出口合同"]);
                    dtTemp = Convert.ToDateTime(ds.Tables[0].Rows[i]["收出口合同登记日期"]);
                    if (nTemp > 2 && 1900 != dtTemp.Value.Date.Year)
                    {
                        CurrentUGR.Cells["出口合同"].Appearance.BackColor = Color.Gray;
                    }
                    else
                    {
                        CurrentUGR.Cells["出口合同"].Appearance.BackColor = clorDefault;
                    }
                }
            }
        }

        public static void ultraGrid1_InitializeRowFilter(Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
        {
            //ultraGrid1.DisplayLayout.Override.RowSizing = RowSizing.AutoFree;
            //foreach (UltraGridColumn ugc in ultraGrid1.DisplayLayout.Bands[0].Columns)
            //    ugc.PerformAutoResize();
            // FILTER ROW FUNCTIONALITY RELATED ULTRAGRID SETTINGS
            //e.Layout.Override.RowFilterAction = RowFilterAction.DisableFilteredOutRows;
            // ----------------------------------------------------------------------------------
            // Enable the the filter row user interface by setting the FilterUIType to FilterRow.
            e.Layout.Override.FilterUIType = FilterUIType.FilterRow;
            //e.Layout.Override.RowFilterMode = RowFilterMode.AllRowsInBand;
            // FilterEvaluationTrigger specifies when UltraGrid applies the filter criteria typed 
            // into a filter row. Default is OnCellValueChange which will cause the UltraGrid to
            // re-filter the data as soon as the user modifies the value of a filter cell.
            e.Layout.Override.FilterEvaluationTrigger = FilterEvaluationTrigger.OnCellValueChange;
            //e.Layout.Override.RowFilterMode = RowFilterMode.AllRowsInBand;
            // By default the UltraGrid selects the type of the filter operand editor based on
            // the column's DataType. For DateTime and boolean columns it uses the column's editors.
            // For other column types it uses the Combo. You can explicitly specify the operand
            // editor style by setting the FilterOperandStyle on the override or the individual
            // columns.

            e.Layout.Override.FilterOperandStyle = FilterOperandStyle.DropDownList;

            // By default UltraGrid displays user interface for selecting the filter operator. 
            // You can set the FilterOperatorLocation to hide this user interface. This
            // property is available on column as well so it can be controlled on a per column
            // basis. Default is WithOperand. This property is exposed off the column as well.
            e.Layout.Override.FilterOperatorLocation = FilterOperatorLocation.WithOperand;

            // By default the UltraGrid uses StartsWith as the filter operator. You use
            // the FilterOperatorDefaultValue property to specify a different filter operator
            // to use. This is the default or the initial filter operator value of the cells
            // in filter row. If filter operator user interface is enabled (FilterOperatorLocation
            // is not set to None) then that ui will be initialized to the value of this
            // property. The user can then change the operator as he/she chooses via the operator
            // drop down.
            e.Layout.Override.FilterOperatorDefaultValue = FilterOperatorDefaultValue.StartsWith;

            // FilterOperatorDropDownItems property can be used to control the options provided
            // to the user for selecting the filter operator. By default UltraGrid bases 
            // what operator options to provide on the column's data type. This property is
            // avaibale on the column as well.
            //e.Layout.Override.FilterOperatorDropDownItems = FilterOperatorDropDownItems.All;

            // By default UltraGrid displays a clear button in each cell of the filter row
            // as well as in the row selector of the filter row. When the user clicks this
            // button the associated filter criteria is cleared. You can use the 
            // FilterClearButtonLocation property to control if and where the filter clear
            // buttons are displayed.
            e.Layout.Override.FilterClearButtonLocation = FilterClearButtonLocation.RowAndCell;

            // Appearance of the filter row can be controlled using the FilterRowAppearance proeprty.
            e.Layout.Override.FilterRowAppearance.BackColor = Color.LightYellow;

            // You can use the FilterRowPrompt to display a prompt in the filter row. By default
            // UltraGrid does not display any prompt in the filter row.
            e.Layout.Override.FilterRowPrompt = "Click here to filter data...";

            // You can use the FilterRowPromptAppearance to change the appearance of the prompt.
            // By default the prompt is transparent and uses the same fore color as the filter row.
            // You can make it non-transparent by setting the appearance' BackColorAlpha property 
            // or by setting the BackColor to a desired value.
            e.Layout.Override.FilterRowPromptAppearance.BackColorAlpha = Alpha.Opaque;

            // By default the prompt is spread across multiple cells if it's bigger than the
            // first cell. You can confine the prompt to a particular cell by setting the
            // SpecialRowPromptField property off the band to the key of a column.
            //e.Layout.Bands[0].SpecialRowPromptField = e.Layout.Bands[0].Columns[0].Key;

            // Display a separator between the filter row other rows. SpecialRowSeparator property 
            // can be used to display separators between various 'special' rows, including for the
            // filter row. This property is a flagged enum property so it can take multiple values.
            e.Layout.Override.SpecialRowSeparator = SpecialRowSeparator.FilterRow;

            // You can control the appearance of the separator using the SpecialRowSeparatorAppearance
            // property.
            e.Layout.Override.SpecialRowSeparatorAppearance.BackColor = Color.FromArgb(233, 242, 199);

            //   UltraGridBand band = e.Layout.Bands[0];
            //   band.ColumnFilters["原币金额"].FilterConditions.Clear();
            //   band.ColumnFilters["原币金额"].FilterConditions.Add(

            //FilterComparisionOperator.GreaterThan, 5);
            //   band.ColumnFilters["原币金额"].FilterConditions.Add(

            //FilterComparisionOperator.LessThan, 10);
            //   band.ColumnFilters["原币金额"].LogicalOperator = FilterLogicalOperator.And;
        }
        private void ultraGrid1_InitializeLayout(object sender, InitializeLayoutEventArgs e)
        {
            ultraGrid1.DisplayLayout.Override.RowSizing = RowSizing.AutoFree;
            if (this.checkBox1.Checked == true)
                ultraGrid1_InitializeRowFilter(e);
            else
                ClassUltraGridCommonSet.ultraGrid1_InitializeRowFilter(e);
            e.Layout.Bands[0].Columns["全选"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.CheckBox;
            for (int i = 1; i < this.ultraGrid1.DisplayLayout.Bands[0].Columns.Count; i++)
            {
                e.Layout.Bands[0].Columns[i].CellMultiLine = DefaultableBoolean.True;
            }

            ultraGrid1.DisplayLayout.Override.WrapHeaderText = Infragistics.Win.DefaultableBoolean.True;
            InitColumnWidth();

            foreach (UltraGridColumn column2 in ultraGrid1.DisplayLayout.Bands[0].Columns)
            {
                string str = column2.Header.Caption;
                if (str == "业务员" || str == "申报年月" || str == "公司" || str == "部门"
                    || str == "订单号" || str == "工厂简称" || str == "合同编号"
                    || str == "柜号" || str == "申报日期" || str == "交财务退税" || str == "是否已收齐")
                {
                    column2.CellAppearance.BackColor = Color.FromArgb(255, 255, 128);
                    column2.CellActivation = Activation.ActivateOnly;
                }
            }
        }

        private void InitColumnWidth()
        {
            ultraGrid1.DisplayLayout.Bands[0].Columns["全选"].Width = 20;
            ultraGrid1.DisplayLayout.Bands[0].Columns["业务员"].Width = 50;
            ultraGrid1.DisplayLayout.Bands[0].Columns["申报年月"].Width = 50;
            ultraGrid1.DisplayLayout.Bands[0].Columns["公司"].Width = 50;
            ultraGrid1.DisplayLayout.Bands[0].Columns["部门"].Width = 60;
            ultraGrid1.DisplayLayout.Bands[0].Columns["订单号"].Width = 75;
            ultraGrid1.DisplayLayout.Bands[0].Columns["工厂简称"].Width = 60;
            ultraGrid1.DisplayLayout.Bands[0].Columns["合同编号"].Width = 75;
            ultraGrid1.DisplayLayout.Bands[0].Columns["柜号"].Width = 90;
            ultraGrid1.DisplayLayout.Bands[0].Columns["申报日期"].Width = 75;
            ultraGrid1.DisplayLayout.Bands[0].Columns["提单"].Width = 50;
            ultraGrid1.DisplayLayout.Bands[0].Columns["入仓单"].Width = 50;
            ultraGrid1.DisplayLayout.Bands[0].Columns["六联单"].Width = 50;
            ultraGrid1.DisplayLayout.Bands[0].Columns["托运单"].Width = 50;
            ultraGrid1.DisplayLayout.Bands[0].Columns["放行条"].Width = 50;
            ultraGrid1.DisplayLayout.Bands[0].Columns["委托书"].Width = 50;
            ultraGrid1.DisplayLayout.Bands[0].Columns["出口合同"].Width = 50;
            ultraGrid1.DisplayLayout.Bands[0].Columns["是否已收齐"].Width = 50;
            ultraGrid1.DisplayLayout.Bands[0].Columns["锁定"].Width = 50;
            ultraGrid1.DisplayLayout.Bands[0].Columns["交财务退税"].Width = 50;
            ultraGrid1.DisplayLayout.Bands[0].Columns["无法追回"].Width = 50;
            ultraGrid1.DisplayLayout.Bands[0].Columns["确认签收"].Width = 60;
        }

        /*
This CreationFilter class will create a CheckBoxUIElement in each Column Header
whose DataType is boolean. It will fire the HeaderCheckBoxClicked event 
whenever the CheckBox is clicked.
Note that in order to maintain the CheckState, this CreationFilter uses the 
Tag proprty of the Header. So if the program uses the tag for something else
this will not work. 
*/
        // Implements the CreationFilter interface		
        public class CheckBoxOnHeader_CreationFilter : IUIElementCreationFilter
        {
            // This event will fire when the CheckBox is clicked. 
            public delegate void HeaderCheckBoxClickedHandler(object sender, HeaderCheckBoxEventArgs e);
            public event HeaderCheckBoxClickedHandler _CLICKED;
            public Dictionary<int, int> m_dicSelectID2RowNo = new Dictionary<int, int>();
            public Infragistics.Win.UltraWinGrid.UltraGrid m_ultraGrid1;
            public void SetParam(Dictionary<int, int> dicSelectID2RowNo, Infragistics.Win.UltraWinGrid.UltraGrid ultraGrid1)
            {
                m_dicSelectID2RowNo = dicSelectID2RowNo;
                m_ultraGrid1 = ultraGrid1;

            }
            public CheckBoxOnHeader_CreationFilter()
            {
                _CLICKED += new HeaderCheckBoxClickedHandler(aCheckBoxOnHeader_CreationFilter_HeaderCheckBoxClicked);
            }

            private void aCheckBoxOnHeader_CreationFilter_HeaderCheckBoxClicked(object sender, CheckBoxOnHeader_CreationFilter.HeaderCheckBoxEventArgs e)
            {
                // Check to see if the column is of type boolean.  If it is, set all the cells in that column to
                // whatever value the header checkbox is.
                if (e.Header.Column.Header.Caption == "全选")
                {
                    //foreach (UltraGridRow aRow in e.Rows)
                    //{
                    //    aRow.Cells[e.Header.Column.Index].Value = (e.CurrentCheckState == CheckState.Checked);
                    //}
                    if (e.CurrentCheckState == CheckState.Checked)
                    {
                        Infragistics.Win.UltraWinGrid.UltraGridRow[] ugr = m_ultraGrid1.Rows.GetFilteredInNonGroupByRows();
                        if (ugr.Length <= 0)
                        {
                            return;
                        }

                        for (int i = 0; i < ugr.Length; i++)
                        {
                            int iIndex = ugr[i].Index;
                            UltraGridRow CurrentUGR = m_ultraGrid1.Rows[iIndex];
                            int nSelectFinRecvMoneyDetailTab_NewID = Convert.ToInt32(CurrentUGR.Cells[0].Value.ToString(), 10);

                            CurrentUGR.Cells["全选"].Value = 1;
                            if (!m_dicSelectID2RowNo.Keys.Contains(nSelectFinRecvMoneyDetailTab_NewID))
                                m_dicSelectID2RowNo.Add(nSelectFinRecvMoneyDetailTab_NewID, iIndex);

                            //else
                            //{
                            //    CurrentUGR.Cells["全选"].Value = 0;
                            //    

                            //}
                        }
                    }
                    else
                    {
                        foreach (int nID in m_dicSelectID2RowNo.Keys)
                        {
                            UltraGridRow CurrentUGR = m_ultraGrid1.Rows[m_dicSelectID2RowNo[nID]];
                            CurrentUGR.Cells["全选"].Value = 0;
                        }

                        m_dicSelectID2RowNo.Clear();
                    }
                }
            }

            // EventArgs used for the HeaderCheckBoxClicked event. This event has to pass in the CheckState and the ColumnHeader
            #region HeaderCheckBoxEventArgs
            public class HeaderCheckBoxEventArgs : EventArgs
            {
                private Infragistics.Win.UltraWinGrid.ColumnHeader mvarColumnHeader;
                private CheckState mvarCheckState;
                private RowsCollection mvarRowsCollection;

                public HeaderCheckBoxEventArgs(Infragistics.Win.UltraWinGrid.ColumnHeader hdrColumnHeader, CheckState chkCheckState, RowsCollection Rows)
                {
                    mvarColumnHeader = hdrColumnHeader;
                    mvarCheckState = chkCheckState;
                    mvarRowsCollection = Rows;
                }

                // Expose the rows collection for the specific row island that the header belongs to
                public RowsCollection Rows
                {
                    get
                    {
                        return mvarRowsCollection;
                    }
                }

                public Infragistics.Win.UltraWinGrid.ColumnHeader Header
                {
                    get
                    {
                        return mvarColumnHeader;
                    }
                }

                public CheckState CurrentCheckState
                {
                    get
                    {
                        return mvarCheckState;
                    }
                    set
                    {
                        mvarCheckState = value;
                    }
                }
            }
            #endregion

            private void aCheckBoxUIElement_ElementClick(Object sender, Infragistics.Win.UIElementEventArgs e)
            {
                // Get the CheckBoxUIElement that was clicked
                CheckBoxUIElement aCheckBoxUIElement = (CheckBoxUIElement)e.Element;

                // Get the Header associated with this particular element
                Infragistics.Win.UltraWinGrid.ColumnHeader aColumnHeader = (Infragistics.Win.UltraWinGrid.ColumnHeader)aCheckBoxUIElement.GetAncestor(typeof(HeaderUIElement)).GetContext(typeof(Infragistics.Win.UltraWinGrid.ColumnHeader));

                // Set the Tag on the Header to the new CheckState
                aColumnHeader.Tag = aCheckBoxUIElement.CheckState;

                // So that we can apply various changes only to the relevant Rows collection that the header belongs to
                HeaderUIElement aHeaderUIElement = aCheckBoxUIElement.GetAncestor(typeof(HeaderUIElement)) as HeaderUIElement;
                RowsCollection hRows = aHeaderUIElement.GetContext(typeof(RowsCollection)) as RowsCollection;

                // Raise an event so the programmer can do something when the CheckState changes
                if (_CLICKED != null)
                    _CLICKED(this, new HeaderCheckBoxEventArgs(aColumnHeader, aCheckBoxUIElement.CheckState, hRows));
            }

            public bool BeforeCreateChildElements(Infragistics.Win.UIElement parent)  // Implements Infragistics.Win.IUIElementCreationFilter.BeforeCreateChildElements
            {
                // Don't need to do anything here
                return false;
            }

            public void AfterCreateChildElements(Infragistics.Win.UIElement parent) // Implements Infragistics.Win.IUIElementCreationFilter.AfterCreateChildElements
            {
                // Check for the HeaderUIElement
                if (parent is HeaderUIElement)
                {
                    // Get the HeaderBase object from the HeaderUIElement
                    Infragistics.Win.UltraWinGrid.HeaderBase aHeader = ((HeaderUIElement)parent).Header;

                    // Only put the checkbox into headers whose DataType is boolean
                    if (aHeader.Column.Header.Caption == "全选")
                    {
                        TextUIElement aTextUIElement;
                        CheckBoxUIElement aCheckBoxUIElement = (CheckBoxUIElement)parent.GetDescendant(typeof(CheckBoxUIElement));

                        // Since the grid sometimes re-uses UIElements, we need to check to make sure 
                        // the header does not already have a CheckBoxUIElement attached to it.
                        // If it does, we just get a reference to the existing CheckBoxUIElement,
                        // and reset its properties.
                        if (aCheckBoxUIElement == null)
                        {
                            //Create a New CheckBoxUIElement
                            aCheckBoxUIElement = new CheckBoxUIElement(parent);
                        }

                        // Get the TextUIElement - this is where the text for the 
                        // Header is displayed. We need this so we can push it to the right
                        // in order to make room for the CheckBox
                        aTextUIElement = (TextUIElement)parent.GetDescendant(typeof(TextUIElement));

                        // Sanity check
                        if (aTextUIElement == null)
                            return;

                        // Get the Header and see if the Tag has been set. If the Tag is 
                        // set, we will assume it's the stored CheckState. This has to be
                        // done in order to maintain the CheckState when the grid repaints and
                        // UIElement are destroyed and recreated. 
                        Infragistics.Win.UltraWinGrid.ColumnHeader aColumnHeader =
                            (Infragistics.Win.UltraWinGrid.ColumnHeader)aCheckBoxUIElement.GetAncestor(typeof(HeaderUIElement))
                            .GetContext(typeof(Infragistics.Win.UltraWinGrid.ColumnHeader));

                        if (aColumnHeader.Tag == null)
                            //If the tag was nothing, this is probably the first time this 
                            //Header is being displayed, so default to Indeterminate
                            aColumnHeader.Tag = CheckState.Indeterminate;
                        else
                            aCheckBoxUIElement.CheckState = (CheckState)aColumnHeader.Tag;

                        // Hook the ElementClick of the CheckBoxUIElement
                        aCheckBoxUIElement.ElementClick += new UIElementEventHandler(aCheckBoxUIElement_ElementClick);

                        // Add the CheckBoxUIElement to the HeaderUIElement
                        parent.ChildElements.Add(aCheckBoxUIElement);

                        // Position the CheckBoxUIElement. The number 3 here is used for 3
                        // pixels of padding between the CheckBox and the edge of the Header.
                        // The CheckBox is shifted down slightly so it is centered in the header.
                        aCheckBoxUIElement.Rect = new Rectangle(parent.Rect.X + 3, parent.Rect.Y + ((parent.Rect.Height - aCheckBoxUIElement.CheckSize.Height) / 2), aCheckBoxUIElement.CheckSize.Width, aCheckBoxUIElement.CheckSize.Height);

                        // Push the TextUIElement to the right a little to make 
                        // room for the CheckBox. 3 pixels of padding are used again. 
                        aTextUIElement.Rect = new Rectangle(aCheckBoxUIElement.Rect.Right + 3, aTextUIElement.Rect.Y, parent.Rect.Width - (aCheckBoxUIElement.Rect.Right - parent.Rect.X), aTextUIElement.Rect.Height);
                    }
                    else
                    {
                        // If the column is not a boolean column, we do not want to have a checkbox in it
                        // Since UIElements can be reused by the grid, there is a chance that one of the
                        // HeaderUIElements that we added a checkbox to for a boolean column header
                        // will be reused in a column that is not boolean.  In this case, we must remove
                        // the checkbox so that it will not appear in an inappropriate column header.
                        CheckBoxUIElement aCheckBoxUIElement = (CheckBoxUIElement)parent.GetDescendant(typeof(CheckBoxUIElement));

                        if (aCheckBoxUIElement != null)
                        {
                            parent.ChildElements.Remove(aCheckBoxUIElement);
                            aCheckBoxUIElement.Dispose();
                        }
                    }
                }
            }
        }

        private void ultraGrid1_CellChange(object sender, CellEventArgs e)
        {
            if (StringComparer.Ordinal.Equals(e.Cell.Column.Key, @"全选"))
            {
                m_bLastModifiedCellIsSelect = true;
                int iIndex = e.Cell.Row.Index;
                if (iIndex < 0)
                    return;
                UltraGridRow CurrentUGR = ultraGrid1.Rows[iIndex];


                int nSelectFinRecvMoneyDetailTab_NewID = Convert.ToInt32(CurrentUGR.Cells[0].Value.ToString(), 10);

                if (e.Cell.Text == "1")
                {
                    if (!m_dicSelectID2RowNo.Keys.Contains(nSelectFinRecvMoneyDetailTab_NewID))
                        m_dicSelectID2RowNo.Add(nSelectFinRecvMoneyDetailTab_NewID, iIndex);
                }
                else
                {
                    if (m_dicSelectID2RowNo.Keys.Contains(nSelectFinRecvMoneyDetailTab_NewID))
                        m_dicSelectID2RowNo.Remove(nSelectFinRecvMoneyDetailTab_NewID);
                }
            }
            else
            {
                m_bLastModifiedCellIsSelect = false;

                if (StringComparer.Ordinal.Equals(e.Cell.Column.Key, @"无法追回"))
                {
                    int iIndex = e.Cell.Row.Index;
                    if (iIndex < 0)
                        return;
                    UltraGridRow CurrentUGR = ultraGrid1.Rows[iIndex];

                    bool bCannotRecover = !Convert.ToBoolean(CurrentUGR.Cells["无法追回"].Value);

                    foreach (int nID in m_dicSelectID2RowNo.Keys)
                    {
                        if (m_dicSelectID2RowNo[nID] == iIndex)
                            continue;

                        UltraGridRow SelectUGR = ultraGrid1.Rows[m_dicSelectID2RowNo[nID]];
                        SelectUGR.Cells["无法追回"].Value = bCannotRecover;
                    }
                }
                else if (StringComparer.Ordinal.Equals(e.Cell.Column.Key, @"锁定"))
                {
                    int iIndex = e.Cell.Row.Index;
                    if (iIndex < 0)
                        return;
                    UltraGridRow CurrentUGR = ultraGrid1.Rows[iIndex];

                    bool bLock = !Convert.ToBoolean(CurrentUGR.Cells["锁定"].Value);

                    foreach (int nID in m_dicSelectID2RowNo.Keys)
                    {
                        if (m_dicSelectID2RowNo[nID] == iIndex)
                            continue;

                        UltraGridRow SelectUGR = ultraGrid1.Rows[m_dicSelectID2RowNo[nID]];
                        SelectUGR.Cells["锁定"].Value = bLock;
                    }
                }
            }         
        }

        private void ultraGrid1_ClickCellButton(object sender, CellEventArgs e)
        {
            string strTemp = e.Cell.Column.Header.Caption;
            if (strTemp == "确认签收")
            {
                try
                {
                    int nIndex = e.Cell.Row.Index;
                    UltraGridRow CurrentUGR = ultraGrid1.Rows[nIndex];

                    int nDG_BackRecoveryMaterialResgistTabID = Convert.ToInt32(CurrentUGR.Cells["DG_BackRecoveryMaterialResgistTabID"].Value.ToString());
                    DGBY.Model.DG_BackRecoveryMaterialResgistTab modelBackRecoveryMaterialTab = m_bllBackRecoveryMaterialResgistTab.GetModel(nDG_BackRecoveryMaterialResgistTabID);

                    int nHxdNoTabID = Convert.ToInt32(CurrentUGR.Cells["HxdNoTabID"].Value);
                    DGBY.Model.HxdNoTab modelHxdNoTab = m_bllHxdNoTab.GetModel(nHxdNoTabID);

                    if (null != modelHxdNoTab)
                    {
                        Boolean bUpdate = false;
                        if (1900 == modelHxdNoTab.HstddjDate.Value.Date.Year)
                        { 
                            if(modelBackRecoveryMaterialTab.td == 3)
                            {
                                modelHxdNoTab.istd = false;
                                modelHxdNoTab.HstddjDate = DateTime.Now.Date;
                                bUpdate = true;
                            }
                            else if (modelBackRecoveryMaterialTab.td == 4)
                            {
                                modelHxdNoTab.istd = true;
                                modelHxdNoTab.HstddjDate = DateTime.Now.Date;
                                bUpdate = true;
                            }
                        }

                        if (1900 == modelHxdNoTab.HSLCDDate.Value.Date.Year)
                        {
                            if (modelBackRecoveryMaterialTab.rcd == 3)
                            {
                                modelHxdNoTab.isrcd = false;
                                modelHxdNoTab.HSLCDDate = DateTime.Now.Date;
                                bUpdate = true;
                            }
                            else if (modelBackRecoveryMaterialTab.rcd == 4)
                            {
                                modelHxdNoTab.isrcd = true;
                                modelHxdNoTab.HSLCDDate = DateTime.Now.Date;
                                bUpdate = true;
                            }
                        }
                        
                        if (1900 == modelHxdNoTab.HSLLDDate.Value.Date.Year)
                        {
                            if (modelBackRecoveryMaterialTab.lld == 3)
                            {
                                modelHxdNoTab.islld = false;
                                modelHxdNoTab.HSLLDDate = DateTime.Now.Date;
                                bUpdate = true;
                            }
                            else if (modelBackRecoveryMaterialTab.lld == 4)
                            {
                                modelHxdNoTab.islld = true;
                                modelHxdNoTab.HSLLDDate = DateTime.Now.Date;
                                bUpdate = true;
                            }
                        }

                        if (1900 == modelHxdNoTab.HSTYDDate.Value.Date.Year)
                        {
                            if (modelBackRecoveryMaterialTab.tyd == 3)
                            {
                                modelHxdNoTab.istyd = false;
                                modelHxdNoTab.HSTYDDate = DateTime.Now.Date;
                                bUpdate = true;
                            }
                            else if (modelBackRecoveryMaterialTab.tyd == 4)
                            {
                                modelHxdNoTab.istyd = true;
                                modelHxdNoTab.HSTYDDate = DateTime.Now.Date;
                                bUpdate = true;
                            }
                        }

                        if (1900 == modelHxdNoTab.HsbdzldjDate.Value.Date.Year)
                        {
                            if (modelBackRecoveryMaterialTab.fxt == 3)
                            {
                                modelHxdNoTab.isfxt = false;
                                modelHxdNoTab.HsbdzldjDate = DateTime.Now.Date;
                                bUpdate = true;
                            }
                            else if (modelBackRecoveryMaterialTab.fxt == 4)
                            {
                                modelHxdNoTab.isfxt = true;
                                modelHxdNoTab.HsbdzldjDate = DateTime.Now.Date;
                                bUpdate = true;
                            }
                        }

                        if (1900 == modelHxdNoTab.QtddjDate.Value.Date.Year)
                        {
                            if (modelBackRecoveryMaterialTab.wts == 3)
                            {
                                modelHxdNoTab.iswts = false;
                                modelHxdNoTab.QtddjDate = DateTime.Now.Date;
                                bUpdate = true;
                            }
                            else if (modelBackRecoveryMaterialTab.wts == 4)
                            {
                                modelHxdNoTab.iswts = true;
                                modelHxdNoTab.QtddjDate = DateTime.Now.Date;
                                bUpdate = true;
                            }
                        }

                        if (1900 == modelHxdNoTab.SCKHTdjDate.Value.Date.Year)
                        {
                            if (modelBackRecoveryMaterialTab.ckht == 4)
                            {
                                modelHxdNoTab.iswts = true;
                                modelHxdNoTab.SCKHTdjDate = DateTime.Now.Date;
                                bUpdate = true;
                            }
                        }

                        if (bUpdate)
                        {
                            m_bllHxdNoTab.Update(modelHxdNoTab);

                            string strContractNo = CurrentUGR.Cells["合同编号"].Value.ToString();
                            Frm_Main.Log2DB(this.Text, "确认签收", strContractNo);      
                        }

                        if (modelBackRecoveryMaterialTab.IsLock = true)
                        {
                            modelBackRecoveryMaterialTab.IsLock = false;
                            m_bllBackRecoveryMaterialResgistTab.Update(modelBackRecoveryMaterialTab);
                        }

                        DisplayCurrentRowColor(modelBackRecoveryMaterialTab, modelHxdNoTab, CurrentUGR, true);
                    }
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }

        private void DisplayCurrentRowColor(DGBY.Model.DG_BackRecoveryMaterialResgistTab modelBackRecoveryMaterialTab, DGBY.Model.HxdNoTab modelHxdNoTab, UltraGridRow CurrentUGR, bool bUpdateInfo)
        {
            if (bUpdateInfo)
            {
                CurrentUGR.Cells["提单"].Value = modelBackRecoveryMaterialTab.td;
                CurrentUGR.Cells["入仓单"].Value = modelBackRecoveryMaterialTab.rcd;
                CurrentUGR.Cells["六联单"].Value = modelBackRecoveryMaterialTab.lld;
                CurrentUGR.Cells["托运单"].Value = modelBackRecoveryMaterialTab.tyd;
                CurrentUGR.Cells["放行条"].Value = modelBackRecoveryMaterialTab.fxt;
                CurrentUGR.Cells["委托书"].Value = modelBackRecoveryMaterialTab.wts;
                CurrentUGR.Cells["出口合同"].Value = modelBackRecoveryMaterialTab.ckht;
                CurrentUGR.Cells["无法追回"].Value = modelBackRecoveryMaterialTab.bCannotRecover;
                CurrentUGR.Cells["锁定"].Value = modelBackRecoveryMaterialTab.IsLock;

                if (modelBackRecoveryMaterialTab.td == 1 || modelBackRecoveryMaterialTab.rcd == 1
                    || modelBackRecoveryMaterialTab.lld == 1 || modelBackRecoveryMaterialTab.tyd == 1
                    || modelBackRecoveryMaterialTab.fxt == 1 || modelBackRecoveryMaterialTab.wts == 1
                    || modelBackRecoveryMaterialTab.ckht == 1)
                {
                    CurrentUGR.Cells["是否已收齐"].Value = '否';
                }
                else
                {
                    CurrentUGR.Cells["是否已收齐"].Value = '是';
                }
            }

            Color clorDefault = CurrentUGR.Cells["全选"].Appearance.BackColor; 
            if (modelBackRecoveryMaterialTab.td > 2 && 1900 != modelHxdNoTab.HstddjDate.Value.Date.Year)
            {
                CurrentUGR.Cells["提单"].Appearance.BackColor = Color.Gray;
            }
            else
            {
                CurrentUGR.Cells["提单"].Appearance.BackColor = clorDefault;
            }


            if (modelBackRecoveryMaterialTab.rcd > 2 && 1900 != modelHxdNoTab.HSLCDDate.Value.Date.Year)
            {
                CurrentUGR.Cells["入仓单"].Appearance.BackColor = Color.Gray;
            }
            else
            {
                CurrentUGR.Cells["入仓单"].Appearance.BackColor = clorDefault;
            }

            if (modelBackRecoveryMaterialTab.lld > 2 && 1900 != modelHxdNoTab.HSLLDDate.Value.Date.Year)
            {
                CurrentUGR.Cells["六联单"].Appearance.BackColor = Color.Gray;
            }
            else
            {
                CurrentUGR.Cells["六联单"].Appearance.BackColor = clorDefault; 
            }

            if (modelBackRecoveryMaterialTab.tyd > 2 && 1900 != modelHxdNoTab.HSTYDDate.Value.Date.Year)
            {
                CurrentUGR.Cells["托运单"].Appearance.BackColor = Color.Gray; 
            }
            else
            {
                CurrentUGR.Cells["托运单"].Appearance.BackColor = clorDefault; 
            }

            if (modelBackRecoveryMaterialTab.fxt > 2 && 1900 != modelHxdNoTab.HsbdzldjDate.Value.Date.Year)
            {
                CurrentUGR.Cells["放行条"].Appearance.BackColor = Color.Gray;
            }
            else
            {
                CurrentUGR.Cells["放行条"].Appearance.BackColor = clorDefault;
            }

            if (modelBackRecoveryMaterialTab.wts > 2 && 1900 != modelHxdNoTab.QtddjDate.Value.Date.Year)
            {
                CurrentUGR.Cells["委托书"].Appearance.BackColor = Color.Gray;
            }
            else
            {
                CurrentUGR.Cells["委托书"].Appearance.BackColor = clorDefault;
            }

            if (modelBackRecoveryMaterialTab.ckht > 2 && 1900 != modelHxdNoTab.SCKHTdjDate.Value.Date.Year)
            {
                CurrentUGR.Cells["出口合同"].Appearance.BackColor = Color.Gray;
            }
            else
            {
                CurrentUGR.Cells["出口合同"].Appearance.BackColor = clorDefault;
            }
        }

        private void ultraGrid1_KeyDown(object sender, KeyEventArgs e)
        {
            switch (e.KeyCode)
            {

                case Keys.Up:
                    {
                        UltraGridCell gridCell = this.ultraGrid1.ActiveCell;
                        if (null == gridCell)
                            return;

                        string strTemp = this.ultraGrid1.ActiveCell.Column.Header.Caption;
                        int nColumnIndex = this.ultraGrid1.ActiveCell.Column.Index;
                        int nIndex = ultraGrid1.ActiveRow.Index;
                        if (nIndex > 0)
                            nIndex--;
                        this.ultraGrid1.PerformAction(UltraGridAction.ExitEditMode, false,
                          false);
                        this.ultraGrid1.PerformAction(UltraGridAction.AboveCell, false,
                          false);
                        e.Handled = true;
                        ultraGrid1.Rows[nIndex].Cells[nColumnIndex].IgnoreRowColActivation = true;
                        ultraGrid1.Rows[nIndex].Cells[nColumnIndex].Activation = Activation.AllowEdit;
                        ultraGrid1.Rows[nIndex].Cells[nColumnIndex].Activate();
                        this.ultraGrid1.PerformAction(UltraGridAction.EnterEditMode, false,
                          false);
                        break;
                    }

                case Keys.Down:
                    {
                        UltraGridCell gridCell = this.ultraGrid1.ActiveCell;
                        if (null == gridCell)
                            return;

                        string strTemp = this.ultraGrid1.ActiveCell.Column.Header.Caption;
                        int nColumnIndex = this.ultraGrid1.ActiveCell.Column.Index;
                        int nIndex = ultraGrid1.ActiveRow.Index;
                        if (nIndex < ultraGrid1.Rows.Count - 1)
                            nIndex++;
                        this.ultraGrid1.PerformAction(UltraGridAction.ExitEditMode, false,
                          false);
                        this.ultraGrid1.PerformAction(UltraGridAction.BelowCell, false,
                          false);
                        e.Handled = true;
                        ultraGrid1.Rows[nIndex].Cells[nColumnIndex].IgnoreRowColActivation = true;
                        ultraGrid1.Rows[nIndex].Cells[nColumnIndex].Activation = Activation.AllowEdit;
                        ultraGrid1.Rows[nIndex].Cells[nColumnIndex].Activate();
                        this.ultraGrid1.PerformAction(UltraGridAction.EnterEditMode, false,
                          false);
                        break;
                    }

                case Keys.Right:
                    this.ultraGrid1.PerformAction(UltraGridAction.ExitEditMode, false,
                      false);
                    this.ultraGrid1.PerformAction(UltraGridAction.NextCellByTab, false,
                      false);
                    e.Handled = true;
                    this.ultraGrid1.PerformAction(UltraGridAction.EnterEditMode, false,
                      false);
                    break;
                case Keys.Left:
                    this.ultraGrid1.PerformAction(UltraGridAction.ExitEditMode, false,
                      false);
                    this.ultraGrid1.PerformAction(UltraGridAction.PrevCellByTab, false,
                      false);
                    e.Handled = true;
                    this.ultraGrid1.PerformAction(UltraGridAction.EnterEditMode, false,
                      false);
                    break;
            }
        }

        private void ultraGrid1_BeforeRowUpdate(object sender, CancelableRowEventArgs e)
        {
            try
            {
                if (m_dicSelectID2RowNo.Count < 2)
                {
                    ModifyGoodsDetail(e);
                }
                else
                {
                    TransModifyGoodsDetail(e);
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
        }

        private bool ModifyGoodsDetail(CancelableRowEventArgs e)
        {
           try
           {
               UltraGridRow CurrentUGR;
               CurrentUGR = ultraGrid1.Rows[e.Row.Index];

               int nDG_BackRecoveryMaterialResgistTabID = Convert.ToInt32(CurrentUGR.Cells["DG_BackRecoveryMaterialResgistTabID"].Value.ToString());
               DGBY.Model.DG_BackRecoveryMaterialResgistTab oldModelBackRecoveryMaterialTab = m_bllBackRecoveryMaterialResgistTab.GetModel(nDG_BackRecoveryMaterialResgistTabID);
         
               if (null == oldModelBackRecoveryMaterialTab)
                   return false;

               bool bUpdate = false;
               bool bUpdateQS = false;

               int nTemp = Convert.ToInt32(CurrentUGR.Cells["提单"].Value);
               if (nTemp != oldModelBackRecoveryMaterialTab.td)
               {
                   oldModelBackRecoveryMaterialTab.td = nTemp;
                   bUpdate = true;

                   if (CurrentUGR.Cells["提单"].Appearance.BackColor == Color.Gray)
                       bUpdateQS = true;
               }

               nTemp = Convert.ToInt32(CurrentUGR.Cells["入仓单"].Value);
               if (nTemp != oldModelBackRecoveryMaterialTab.rcd)
               {
                   oldModelBackRecoveryMaterialTab.rcd = nTemp;
                   bUpdate = true;

                   if (CurrentUGR.Cells["入仓单"].Appearance.BackColor == Color.Gray)
                       bUpdateQS = true;
               }

               nTemp = Convert.ToInt32(CurrentUGR.Cells["六联单"].Value);
               if (nTemp != oldModelBackRecoveryMaterialTab.lld)
               {
                   oldModelBackRecoveryMaterialTab.lld = nTemp;
                   bUpdate = true;

                   if (CurrentUGR.Cells["六联单"].Appearance.BackColor == Color.Gray)
                       bUpdateQS = true;
               }

               nTemp = Convert.ToInt32(CurrentUGR.Cells["托运单"].Value);
               if (nTemp != oldModelBackRecoveryMaterialTab.tyd)
               {
                   oldModelBackRecoveryMaterialTab.tyd = nTemp;
                   bUpdate = true;

                   if (CurrentUGR.Cells["托运单"].Appearance.BackColor == Color.Gray)
                       bUpdateQS = true;
               }

               nTemp = Convert.ToInt32(CurrentUGR.Cells["放行条"].Value);
               if (nTemp != oldModelBackRecoveryMaterialTab.fxt)
               {
                   oldModelBackRecoveryMaterialTab.fxt = nTemp;
                   bUpdate = true;

                   if (CurrentUGR.Cells["放行条"].Appearance.BackColor == Color.Gray)
                       bUpdateQS = true;
               }

               nTemp = Convert.ToInt32(CurrentUGR.Cells["委托书"].Value);
               if (nTemp != oldModelBackRecoveryMaterialTab.wts)
               {
                   oldModelBackRecoveryMaterialTab.wts = nTemp;
                   bUpdate = true;

                   if (CurrentUGR.Cells["委托书"].Appearance.BackColor == Color.Gray)
                       bUpdateQS = true;
               }

               nTemp = Convert.ToInt32(CurrentUGR.Cells["出口合同"].Value);
               if (nTemp != oldModelBackRecoveryMaterialTab.ckht)
               {
                   oldModelBackRecoveryMaterialTab.ckht = nTemp;
                   bUpdate = true;

                   if (CurrentUGR.Cells["出口合同"].Appearance.BackColor == Color.Gray)
                       bUpdateQS = true;
               }

               Boolean bCannotRecover = Convert.ToBoolean(CurrentUGR.Cells["无法追回"].Value);
               if (bCannotRecover != oldModelBackRecoveryMaterialTab.bCannotRecover)
               {
                   oldModelBackRecoveryMaterialTab.bCannotRecover = bCannotRecover;
                   bUpdate = true;
               }

               Boolean bLock = Convert.ToBoolean(CurrentUGR.Cells["锁定"].Value);
               if (bLock != oldModelBackRecoveryMaterialTab.IsLock)
               {
                   oldModelBackRecoveryMaterialTab.IsLock = bLock;
                   bUpdate = true;
               }


               if (bUpdate)
               {
                   int nHxdNoTabID = Convert.ToInt32(CurrentUGR.Cells["HxdNoTabID"].Value);
                   DGBY.Model.HxdNoTab modelHxdNoTab = m_bllHxdNoTab.GetModel(nHxdNoTabID);

                   if (bUpdateQS)
                   {
                       DialogResult dr = MessageBox.Show(CurrentUGR.Cells["合同编号"].Text + "已确认签收，确实要修改吗？", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                       if (dr == DialogResult.Cancel)
                       {
                           e.Cancel = true;
                           return false;
                       }
                   }

                   m_bllBackRecoveryMaterialResgistTab.Update(oldModelBackRecoveryMaterialTab);
                   CurrentUGR.Cells["无法追回"].Value = oldModelBackRecoveryMaterialTab.bCannotRecover;

                   string strContractNo = CurrentUGR.Cells["合同编号"].Value.ToString();
                   Frm_Main.Log2DB(this.Text, "修改", strContractNo);

                   DisplayCurrentRowColor(oldModelBackRecoveryMaterialTab, modelHxdNoTab, CurrentUGR, true);
               }

               return true;
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return false;
            }
        }

        private bool TransModifyGoodsDetail(CancelableRowEventArgs e)
        {
            m_SQLStringList.Clear();
            m_arrayList.Clear();

            bool bSelUpdate = false;

            try
            {
                int nAppendNum = 0;
                string strContractNo = "";
 
                bool bUpdateQS = false;

                UltraGridRow SelectUGR = ultraGrid1.Rows[e.Row.Index];
                int nDG_BackRecoveryMaterialResgistTabID = Convert.ToInt32(SelectUGR.Cells["DG_BackRecoveryMaterialResgistTabID"].Value.ToString());
                DGBY.Model.DG_BackRecoveryMaterialResgistTab oldModelBackRecoveryMaterialTab = m_bllBackRecoveryMaterialResgistTab.GetModel(nDG_BackRecoveryMaterialResgistTabID);
                if (null == oldModelBackRecoveryMaterialTab)
                    return false;

                int nTemp = Convert.ToInt32(SelectUGR.Cells["提单"].Value);
                if (nTemp != oldModelBackRecoveryMaterialTab.td)
                {
                    oldModelBackRecoveryMaterialTab.td = nTemp;
                    bSelUpdate = true;

                    if (SelectUGR.Cells["提单"].Appearance.BackColor == Color.Gray)
                        bUpdateQS = true;
                }

                nTemp = Convert.ToInt32(SelectUGR.Cells["入仓单"].Value);
                if (nTemp != oldModelBackRecoveryMaterialTab.rcd)
                {
                    oldModelBackRecoveryMaterialTab.rcd = nTemp;
                    bSelUpdate = true;

                    if (SelectUGR.Cells["入仓单"].Appearance.BackColor == Color.Gray)
                        bUpdateQS = true;
                }

                nTemp = Convert.ToInt32(SelectUGR.Cells["六联单"].Value);
                if (nTemp != oldModelBackRecoveryMaterialTab.lld)
                {
                    oldModelBackRecoveryMaterialTab.lld = nTemp;
                    bSelUpdate = true;

                    if (SelectUGR.Cells["六联单"].Appearance.BackColor == Color.Gray)
                        bUpdateQS = true;
                }

                nTemp = Convert.ToInt32(SelectUGR.Cells["托运单"].Value);
                if (nTemp != oldModelBackRecoveryMaterialTab.tyd)
                {
                    oldModelBackRecoveryMaterialTab.tyd = nTemp;
                    bSelUpdate = true;

                    if (SelectUGR.Cells["托运单"].Appearance.BackColor == Color.Gray)
                        bUpdateQS = true;
                }

                nTemp = Convert.ToInt32(SelectUGR.Cells["放行条"].Value);
                if (nTemp != oldModelBackRecoveryMaterialTab.fxt)
                {
                    oldModelBackRecoveryMaterialTab.fxt = nTemp;
                    bSelUpdate = true;

                    if (SelectUGR.Cells["放行条"].Appearance.BackColor == Color.Gray)
                        bUpdateQS = true;
                }

                nTemp = Convert.ToInt32(SelectUGR.Cells["委托书"].Value);
                if (nTemp != oldModelBackRecoveryMaterialTab.wts)
                {
                    oldModelBackRecoveryMaterialTab.wts = nTemp;
                    bSelUpdate = true;

                    if (SelectUGR.Cells["委托书"].Appearance.BackColor == Color.Gray)
                        bUpdateQS = true;
                }

                nTemp = Convert.ToInt32(SelectUGR.Cells["出口合同"].Value);
                if (nTemp != oldModelBackRecoveryMaterialTab.ckht)
                {
                    oldModelBackRecoveryMaterialTab.ckht = nTemp;
                    bSelUpdate = true;

                    if (SelectUGR.Cells["出口合同"].Appearance.BackColor == Color.Gray)
                        bUpdateQS = true;
                }

                Boolean bCannotRecover = Convert.ToBoolean(SelectUGR.Cells["无法追回"].Value);
                if (bCannotRecover != oldModelBackRecoveryMaterialTab.bCannotRecover)
                {
                    oldModelBackRecoveryMaterialTab.bCannotRecover = bCannotRecover;
                    bSelUpdate = true;
                }

                Boolean bLock = Convert.ToBoolean(SelectUGR.Cells["锁定"].Value);
                if (bLock != oldModelBackRecoveryMaterialTab.IsLock)
                {
                    oldModelBackRecoveryMaterialTab.IsLock = bLock;
                    bSelUpdate = true;
                }

                if (bSelUpdate)
                {
                    DialogResult dr = MessageBox.Show("确实要批量修改吗？", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                    if (dr == DialogResult.Cancel)
                    {
                        e.Cancel = true;

                        UpdateAllRows(true);
                        return false;
                    }
                    else
                    {
                        if (bUpdateQS)
                        {
                            dr = MessageBox.Show("已确认签收，确实要修改吗？", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                            if (dr == DialogResult.Cancel)
                            {
                                e.Cancel = true;

                                UpdateAllRows(true);
                                return false;
                            }
                        }
                    }

                    m_bllBackRecoveryMaterialResgistTab.TransUpdate(oldModelBackRecoveryMaterialTab
                        , m_SQLStringList, m_arrayList, nAppendNum++);

                    strContractNo += SelectUGR.Cells["合同编号"].Value.ToString() + (" ");
                }

                //批量修改
                foreach (int nID in m_dicSelectID2RowNo.Keys)
                {
                    if (m_dicSelectID2RowNo[nID] == e.Row.Index)
                        continue;

                    SelectUGR = ultraGrid1.Rows[m_dicSelectID2RowNo[nID]];
                    nDG_BackRecoveryMaterialResgistTabID = Convert.ToInt32(SelectUGR.Cells["DG_BackRecoveryMaterialResgistTabID"].Value.ToString());

                    oldModelBackRecoveryMaterialTab = m_bllBackRecoveryMaterialResgistTab.GetModel(nDG_BackRecoveryMaterialResgistTabID);
                    if (null == oldModelBackRecoveryMaterialTab)
                        continue;

                    bool bUpdate = false;

                    nTemp = Convert.ToInt32(SelectUGR.Cells["提单"].Value);
                    if (nTemp != oldModelBackRecoveryMaterialTab.td)
                    {
                        oldModelBackRecoveryMaterialTab.td = nTemp;
                        bUpdate = true;
                    }

                    nTemp = Convert.ToInt32(SelectUGR.Cells["入仓单"].Value);
                    if (nTemp != oldModelBackRecoveryMaterialTab.rcd)
                    {
                        oldModelBackRecoveryMaterialTab.rcd = nTemp;
                        bUpdate = true;
                    }

                    nTemp = Convert.ToInt32(SelectUGR.Cells["六联单"].Value);
                    if (nTemp != oldModelBackRecoveryMaterialTab.lld)
                    {
                        oldModelBackRecoveryMaterialTab.lld = nTemp;
                        bUpdate = true;
                    }

                    nTemp = Convert.ToInt32(SelectUGR.Cells["托运单"].Value);
                    if (nTemp != oldModelBackRecoveryMaterialTab.tyd)
                    {
                        oldModelBackRecoveryMaterialTab.tyd = nTemp;
                        bUpdate = true;
                    }

                    nTemp = Convert.ToInt32(SelectUGR.Cells["放行条"].Value);
                    if (nTemp != oldModelBackRecoveryMaterialTab.fxt)
                    {
                        oldModelBackRecoveryMaterialTab.fxt = nTemp;
                        bUpdate = true;
                    }

                    nTemp = Convert.ToInt32(SelectUGR.Cells["委托书"].Value);
                    if (nTemp != oldModelBackRecoveryMaterialTab.wts)
                    {
                        oldModelBackRecoveryMaterialTab.wts = nTemp;
                        bUpdate = true;
                    }

                    nTemp = Convert.ToInt32(SelectUGR.Cells["出口合同"].Value);
                    if (nTemp != oldModelBackRecoveryMaterialTab.ckht)
                    {
                        oldModelBackRecoveryMaterialTab.ckht = nTemp;
                        bUpdate = true;
                    }

                    bCannotRecover = Convert.ToBoolean(SelectUGR.Cells["无法追回"].Value);
                    if (bCannotRecover != oldModelBackRecoveryMaterialTab.bCannotRecover)
                    {
                        oldModelBackRecoveryMaterialTab.bCannotRecover = bCannotRecover;
                        bUpdate = true;
                    }

                    bLock = Convert.ToBoolean(SelectUGR.Cells["锁定"].Value);
                    if (bLock != oldModelBackRecoveryMaterialTab.IsLock)
                    {
                        oldModelBackRecoveryMaterialTab.IsLock = bLock;
                        bUpdate = true;
                    }

                    if (bUpdate)
                    {           
                        m_bllBackRecoveryMaterialResgistTab.TransUpdate(oldModelBackRecoveryMaterialTab
                            , m_SQLStringList, m_arrayList, nAppendNum++);

                        strContractNo += SelectUGR.Cells["合同编号"].Value.ToString() + (" ");
                    }
                }

                if (bSelUpdate)
                {
                    m_bllSJPackingTab.ExecuteSqlTran(m_SQLStringList, m_arrayList);
                    Frm_Main.Log2DB(this.Text, "批量修改", strContractNo);

                    UpdateAllRows(true);

                    //取消选择
                    CancelSelectAllRow();
                }

                return true;
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return false;
            }
        }

        private void CancelSelectAllRow()
        {
            foreach (int nID in m_dicSelectID2RowNo.Keys)
            {
                UltraGridRow SelectUGR = ultraGrid1.Rows[m_dicSelectID2RowNo[nID]];
                if (null != SelectUGR)
                {
                    SelectUGR.Cells["全选"].Value = 0;
                    
                    //m_dicSelectID2RowNo.Remove(m_dicSelectID2RowNo[nID]);
                }
            }

            m_dicSelectID2RowNo.Clear();
        }

        private void UpdateAllRows(bool bUpdateInfo)
        { 
            foreach (int nID in m_dicSelectID2RowNo.Keys)
            {
                UltraGridRow SelectUGR = ultraGrid1.Rows[m_dicSelectID2RowNo[nID]];
                int nDG_BackRecoveryMaterialResgistTabID = Convert.ToInt32(SelectUGR.Cells["DG_BackRecoveryMaterialResgistTabID"].Value.ToString());
                DGBY.Model.DG_BackRecoveryMaterialResgistTab oldModelBackRecoveryMaterialTab = m_bllBackRecoveryMaterialResgistTab.GetModel(nDG_BackRecoveryMaterialResgistTabID);

                SelectUGR.Cells["无法追回"].Value = oldModelBackRecoveryMaterialTab.bCannotRecover;
                int nHxdNoTabID = Convert.ToInt32(SelectUGR.Cells["HxdNoTabID"].Value);
                DGBY.Model.HxdNoTab modelHxdNoTab = m_bllHxdNoTab.GetModel(nHxdNoTabID);
                DisplayCurrentRowColor(oldModelBackRecoveryMaterialTab, modelHxdNoTab, SelectUGR, bUpdateInfo);
            }
        }

        private void ultraGrid1_BeforeCellUpdate(object sender, BeforeCellUpdateEventArgs e)
        {
            int nIndex = e.Cell.Row.Index;
            if (nIndex < 0)
                return;

            UltraGridRow CurrentUGR = ultraGrid1.Rows[nIndex];

            if (e.Cell.Column.Key == "提单")
            {
                if (Convert.ToInt32(CurrentUGR.Cells["提单"].Value) == 2
                && CurrentUGR.Cells["提单"].Text != "")
                {
                    MessageBox.Show("因出口方式限制，该提单不允许修改！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    e.Cancel = true;

                    return;
                }
                else if (CurrentUGR.Cells["提单"].Text == "")
                {
                    MessageBox.Show("提单不允许设置为空！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    e.Cancel = true;

                    return;
                }
            }
            else if (e.Cell.Column.Key == "入仓单")
            {
                if (Convert.ToInt32(CurrentUGR.Cells["入仓单"].Value) == 2
                    && CurrentUGR.Cells["入仓单"].Text != "")
                {
                    MessageBox.Show("因出口方式限制，该入仓单不允许修改！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    e.Cancel = true;

                    return;
                }
                else if (CurrentUGR.Cells["入仓单"].Text == "")
                {
                    MessageBox.Show("入仓单不允许设置为空！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    e.Cancel = true;

                    return;
                }
            }

            if (e.Cell.Column.Key == "六联单")
            {
                if (Convert.ToInt32(CurrentUGR.Cells["六联单"].Value) == 2
                 && CurrentUGR.Cells["六联单"].Text != "")
                {
                    MessageBox.Show("因出口方式限制，该六联单不允许修改！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    e.Cancel = true;

                    return;
                }
                else if (CurrentUGR.Cells["六联单"].Text == "")
                {
                    MessageBox.Show("六联单不允许设置为空！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    e.Cancel = true;

                    return;
                }
            }

            if (e.Cell.Column.Key == "托运单")
            {
                if (Convert.ToInt32(CurrentUGR.Cells["托运单"].Value) == 2
                    && CurrentUGR.Cells["托运单"].Text != "")
                {
                    MessageBox.Show("因出口方式限制，该托运单不允许修改！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    e.Cancel = true;

                    return;
                }
                else if (CurrentUGR.Cells["托运单"].Text == "")
                {
                    MessageBox.Show("托运单不允许设置为空！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    e.Cancel = true;

                    return;
                }
            }

            if (e.Cell.Column.Key == "放行条")
            {
                if (Convert.ToInt32(CurrentUGR.Cells["放行条"].Value) == 2
                    && CurrentUGR.Cells["放行条"].Text != "")
                {
                    MessageBox.Show("因出口方式限制，该放行条不允许修改！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    e.Cancel = true;

                    return;
                }
                else if (CurrentUGR.Cells["放行条"].Text == "")
                {
                    MessageBox.Show("放行条不允许设置为空！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    e.Cancel = true;

                    return;
                }
            }

            if (e.Cell.Column.Key == "委托书")
            {
                if (Convert.ToInt32(CurrentUGR.Cells["委托书"].Value) == 2
                    && CurrentUGR.Cells["委托书"].Text != "")
                {
                    MessageBox.Show("因出口方式限制，该委托书不允许修改！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    e.Cancel = true;

                    return;
                }
                else if (CurrentUGR.Cells["委托书"].Text == "")
                {
                    MessageBox.Show("委托书不允许设置为空！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    e.Cancel = true;

                    return;
                }
            }
        }

        private void ultraGrid1_AfterCellUpdate(object sender, CellEventArgs e)
        {
            int nIndex = e.Cell.Row.Index;
            if (nIndex < 0)
                return;

            if (nIndex != this.ultraGrid1.ActiveRow.Index)
                return;

            string strColoumn = e.Cell.Column.Key;

            if (e.Cell.Column.Key != "提单"
                && e.Cell.Column.Key != "入仓单"
                && e.Cell.Column.Key != "六联单"
                && e.Cell.Column.Key != "托运单"
                && e.Cell.Column.Key != "放行条"
                && e.Cell.Column.Key != "委托书"
                && e.Cell.Column.Key != "出口合同"
                && e.Cell.Column.Key != "无法追回"
                && e.Cell.Column.Key != "锁定")
                return;

            UltraGridRow CurrentUGR = ultraGrid1.Rows[nIndex];
            int nDG_BackRecoveryMaterialResgistTabID = Convert.ToInt32(CurrentUGR.Cells["DG_BackRecoveryMaterialResgistTabID"].Value.ToString());

            foreach (int nID in m_dicSelectID2RowNo.Keys)
            {
                UltraGridRow SelectUGR = ultraGrid1.Rows[m_dicSelectID2RowNo[nID]];

                int nNewDG_BackRecoveryMaterialResgistTabID = Convert.ToInt32(SelectUGR.Cells["DG_BackRecoveryMaterialResgistTabID"].Value.ToString());
                if (nDG_BackRecoveryMaterialResgistTabID == nNewDG_BackRecoveryMaterialResgistTabID)
                    continue;

                if (e.Cell.Column.Key != "无法追回" || e.Cell.Column.Key != "锁定")
                {
                    if (Convert.ToInt32(SelectUGR.Cells[strColoumn].Value) == 2)
                        continue;
                }

                SelectUGR.Cells[strColoumn].Value = CurrentUGR.Cells[strColoumn].Value;
            }
        }

        private void buttonExportToExcel_Click(object sender, EventArgs e)
        {
            DataTable dt = (DataTable)ultraGrid1.DataSource;

            if (dt != null)
            {
                if (dt.Rows.Count > 0)
                {
                    SaveFileDialog sfd = new SaveFileDialog();
                    sfd.Filter = "Excel文件(*.xls)|*.xls";
                    string outFile = "";

                    if (sfd.ShowDialog() == DialogResult.OK)
                    {
                        outFile = sfd.FileName;
                    }
                    else
                    {
                        return;
                    }

                    ultraGrid1.DisplayLayout.Bands[0].Columns["全选"].Hidden = true;
                    ultraGrid1.DisplayLayout.Bands[0].Columns["业务员"].Hidden = true;
                    ultraGrid1.DisplayLayout.Bands[0].Columns["申报年月"].Hidden = true;
                    ultraGrid1.DisplayLayout.Bands[0].Columns["公司"].Hidden = true;
                    ultraGrid1.DisplayLayout.Bands[0].Columns["部门"].Hidden = true;
                    ultraGrid1.DisplayLayout.Bands[0].Columns["交财务退税"].Hidden = true;
                    ultraGrid1.DisplayLayout.Bands[0].Columns["无法追回"].Hidden = true;
                    ultraGrid1.DisplayLayout.Bands[0].Columns["确认签收"].Hidden = true;
                    ultraGridExcelExporter1.Export(ultraGrid1, outFile);
                }
            }
        }

        private void ultraGridExcelExporter1_EndExport(object sender, Infragistics.Win.UltraWinGrid.ExcelExport.EndExportEventArgs e)
        {
            ultraGrid1.DisplayLayout.Bands[0].Columns["全选"].Hidden = false;
            ultraGrid1.DisplayLayout.Bands[0].Columns["业务员"].Hidden = false;
            ultraGrid1.DisplayLayout.Bands[0].Columns["申报年月"].Hidden = false;
            ultraGrid1.DisplayLayout.Bands[0].Columns["公司"].Hidden = false;
            ultraGrid1.DisplayLayout.Bands[0].Columns["部门"].Hidden = false;
            ultraGrid1.DisplayLayout.Bands[0].Columns["交财务退税"].Hidden = false;
            ultraGrid1.DisplayLayout.Bands[0].Columns["无法追回"].Hidden = false;
            ultraGrid1.DisplayLayout.Bands[0].Columns["确认签收"].Hidden = false;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            m_bHiddenBackInfo = !m_bHiddenBackInfo;

            if (m_bHiddenBackInfo)
            {
                this.bt_HiddenBackInfo.Text = "隐藏已回齐资料";

                ShowAllRecord(@" DG_BackRecoveryMaterialResgistTab.td != 1 
                    and DG_BackRecoveryMaterialResgistTab.rcd != 1
                    and DG_BackRecoveryMaterialResgistTab.lld != 1
                    and DG_BackRecoveryMaterialResgistTab.tyd != 1
                    and DG_BackRecoveryMaterialResgistTab.fxt != 1
                    and DG_BackRecoveryMaterialResgistTab.wts != 1
                    and DG_BackRecoveryMaterialResgistTab.ckht != 1");
            }
            else
            {
                this.bt_HiddenBackInfo.Text = "显示已回齐资料";

                ShowAllRecord(@" DG_BackRecoveryMaterialResgistTab.td = 1 
                    or DG_BackRecoveryMaterialResgistTab.rcd = 1
                    or DG_BackRecoveryMaterialResgistTab.lld = 1
                    or DG_BackRecoveryMaterialResgistTab.tyd = 1
                    or DG_BackRecoveryMaterialResgistTab.fxt = 1
                    or DG_BackRecoveryMaterialResgistTab.wts = 1
                    or DG_BackRecoveryMaterialResgistTab.ckht = 1");
            }
        }

        private void buttonViewContract_Click(object sender, EventArgs e)
        {
            List<object> lstO = this.ultraGrid1.DisplayLayout.Bands[0].ColumnFilters.All.ToList();

            string strColumnName;
            string strColumnValue;
            string strTableColumnValue;
            StringBuilder strSql = new StringBuilder();
            strSql = strSql.Append(m_strSqlConditions);

            foreach (object o in lstO)
            {
                ColumnFilter cf = (ColumnFilter)o;
                strColumnName = cf.Column.Key;
                strColumnValue = cf.FilterConditions.Count > 0 ? ((FilterCondition)cf.FilterConditions.All[0]).CompareValue.ToString() : "";

                if (!string.IsNullOrEmpty(strColumnValue))
                {
                    strTableColumnValue = GetTableColumnValue(strColumnName);
                    if (string.IsNullOrEmpty(strTableColumnValue.ToString()))
                        continue;

                    if (string.IsNullOrEmpty(strSql.ToString()))
                    {
                        strSql = strSql.Append(" " + strTableColumnValue + "='" + strColumnValue + "'");
                    }
                    else
                    {
                        strSql = strSql.Append(" and " + strTableColumnValue + "='" + strColumnValue + "'");
                    }
                }
            }

            if (string.IsNullOrEmpty(strSql.ToString()))
            {
                strSql = strSql.Append(" DG_BackRecoveryMaterialResgistTab.IsLock = 1");
            }
            else
            {
                strSql = strSql.Append(" and DG_BackRecoveryMaterialResgistTab.IsLock = 1");
            }

            ShowAllRecord(strSql.ToString());
        }

        private string GetTableColumnValue(string strColumnName)
        {
            string strTableColumnValue = "";

            if (strColumnName == "合同编号")
            {
                strTableColumnValue = "PaidanRegisterTab.ContractCode";
            }
            else if (strColumnName == "业务员")
            {
                strTableColumnValue = "T_ACL_User.Name";
            }
            else if (strColumnName == "申报年月")
            {
                strTableColumnValue = @"case when Year(HxdNoTab.SBDate) >= 1900 and HxdNoTab.HxdNo >= 1000000001 then CONVERT(varchar(6), HxdNoTab.TongJDate, 112)
when Year(HxdNoTab.SBDate) = 1900 and HxdNoTab.HxdNo < 1000000001 then CONVERT(varchar(6), HxdNoTab.TongJDate, 112)
when Year(HxdNoTab.SBDate) > 1900 and HxdNoTab.HxdNo < 1000000001 then CONVERT(varchar(6), HxdNoTab.SBDate, 112)
else '' end";
            }
            else if (strColumnName == "订单号")
            {
                strTableColumnValue = "PaidanRegisterTab.DingDanCode";
            }
            else if (strColumnName == "工厂简称")
            {
                strTableColumnValue = "FactoryDataTab.FactoryNameJX";
            }
            else if (strColumnName == "柜号")
            {
                strTableColumnValue = "dbo.f_CargoBoxNoCollectFun(PaidanRegisterTab.PaidanRegisterTabID)";
            }
            else if (strColumnName == "申报日期")
            {
                strTableColumnValue = "case when year(HxdNoTab.SBDate) = 1900 then '' else HxdNoTab.SBDate end";
            }
            else if (strColumnName == "公司")
            {
                strTableColumnValue = "BYCompanyTab.CompanyNameJX";
            }
            else if (strColumnName == "部门")
            {
                strTableColumnValue = "BYDepartTab.DepartName";
            }
            else if (strColumnName == "提单")
            {
                strTableColumnValue = "DG_BackRecoveryMaterialResgistTab.td";
            }
            else if (strColumnName == "入仓单")
            {
                strTableColumnValue = "DG_BackRecoveryMaterialResgistTab.rcd";
            }
            else if (strColumnName == "六联单")
            {
                strTableColumnValue = "DG_BackRecoveryMaterialResgistTab.lld";
            }
            else if (strColumnName == "托运单")
            {
                strTableColumnValue = "DG_BackRecoveryMaterialResgistTab.tyd";
            }
            else if (strColumnName == "放行条")
            {
                strTableColumnValue = "DG_BackRecoveryMaterialResgistTab.fxt";
            }
            else if (strColumnName == "委托书")
            {
                strTableColumnValue = "DG_BackRecoveryMaterialResgistTab.wts";
            }
            else if (strColumnName == "出口合同")
            {
                strTableColumnValue = "DG_BackRecoveryMaterialResgistTab.ckht";
            }
            else if (strColumnName == "是否已收齐")
            {
                strTableColumnValue = @"case when DG_BackRecoveryMaterialResgistTab.td = 1 
 or DG_BackRecoveryMaterialResgistTab.rcd =1 
 or DG_BackRecoveryMaterialResgistTab.lld =1 
 or DG_BackRecoveryMaterialResgistTab.tyd =1
 or DG_BackRecoveryMaterialResgistTab.fxt =1
 or DG_BackRecoveryMaterialResgistTab.wts =1
 or DG_BackRecoveryMaterialResgistTab.ckht =1 then '否' else '是' end";
            }
            else if (strColumnName == "交财务退税")
            {
                strTableColumnValue = "case when year(HxdNoTab.JcwTszldDate) = 1900 then '' else '是' end";
            }
            else if (strColumnName == "无法追回")
            {
                strTableColumnValue = "DG_BackRecoveryMaterialResgistTab.bCannotRecover";
            }

            return strTableColumnValue;
        }
    }
}
